package com.ztsoft.user.controller.user;

import com.ztsoft.user.pojo.entity.user.SysDept;
import com.ztsoft.user.pojo.vo.user.SysDeptVo;
import com.ztsoft.user.service.user.SysDeptService;
import com.ztsoft.user.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/dept")
@CrossOrigin("*")
@Api(tags = "部门控制层")
public class SysDeptController {

    @Resource
    private SysDeptService sysDeptService;

    @GetMapping("/queryByPage")
    @ApiOperation(value = "查询部门", notes = "带分页的条件查询")
    public Result<Object> queryByPage(SysDept dept, Integer currentPage, Integer pageSize) {
        return sysDeptService.queryDeptByPage(dept, currentPage, pageSize);
    }

    @GetMapping("/queryTreeSelect")
    @ApiOperation(value = "查询树状部门", notes = "树状结构的部门")
    public Result<Object> queryTreeSelect() {
        return sysDeptService.queryDeptTreeSelect();
    }

    @GetMapping("/queryTree")
    @ApiOperation(value = "查询部门树", notes = "动态表格查询部门列表")
    public Result<Object> queryDeptTree() {
        return sysDeptService.queryDeptTree();
    }

    @PostMapping("/add")
    @ApiOperation(value = "添加部门", notes = "添加部门")
    public Result<Object> add(@RequestBody SysDeptVo sysDeptVo) {
        return sysDeptService.addDept(sysDeptVo);
    }

    @PutMapping("/update")
    @ApiOperation(value = "更新部门", notes = "更新部门")
    public Result<Object> update(@RequestBody SysDeptVo sysDeptVo) {
        return sysDeptService.updateDept(sysDeptVo);
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除部门", notes = "按照id删除部门")
    public Result<Object> delete(@PathVariable("id") Long id) {
        return sysDeptService.deleteDept(id);
    }

}